/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.instrumentation;

import picounit.Instrumentation;
import picounit.features.failures_first.ProblemTracker;

import java.lang.reflect.Method;

public class InstrumentationImpl implements Instrumentation, InstrumentationController {
	private boolean isLast;
	private boolean isFirst;
	
	private int numTests;
	private int numFailures;
	private int numErrors;
	
	private String currentTestClass;
	private String currentTestName;
	private final ProblemTracker problemTracker;
	
	public InstrumentationImpl(ProblemTracker problemTracker) {
		this.problemTracker = problemTracker;
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// Instrumentation methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	public boolean isFirst() {
		return isFirst;
	}

	public boolean isLast() {
		return isLast;
	}
	
	public String currentTestClass() {
		return currentTestClass;
	}

	public String currentTestName() {
		return currentTestName;
	}

	public int numTests() {
		return numTests;
	}

	public int numFailures() {
		return numFailures;
	}

	public int numErrors() {
		return numErrors;
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// InstrumentationController methods
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	public void setIsFirst(boolean isFirst) {
		this.isFirst = isFirst;
	}

	public void setIsLast(boolean isLast) {
		this.isLast = isLast;
	}
	
	public void setCurrentTest(String className, String testName) {
		this.currentTestClass = className;
		this.currentTestName = testName;
	}

	public void incrementTests() {
		numTests++;
	}

	public void addFailure(Class testClass, Method testMethod) {
		problemTracker.increaseFailures(testClass);

		numFailures++;
	}

	public void addError(Class testClass, Method testMethod) {
		problemTracker.increaseErrors(testClass);

		numErrors++;
	}
}
